from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `menu` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `create_time` DATETIME(6) NOT NULL  COMMENT '创建时间' DEFAULT CURRENT_TIMESTAMP(6),
    `update_time` DATETIME(6) NOT NULL  COMMENT '更新时间' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `name` VARCHAR(32) NOT NULL UNIQUE COMMENT '菜单名称',
    `level` INT   COMMENT '菜单等级',
    `path` VARCHAR(32) NOT NULL  COMMENT '菜单路径',
    `pid_id` INT COMMENT '父级菜单',
    CONSTRAINT `fk_menu_menu_9bb74577` FOREIGN KEY (`pid_id`) REFERENCES `menu` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='菜单表';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP TABLE IF EXISTS `menu`;"""
